/* 聊天区域 */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px); /* 确保占满可用高度 */
    min-height: 0;
    overflow: hidden;
    padding: 0 16px;
    background-color: #f9fafb;
}

.chat-messages {
    flex: 1; /* 占据所有剩余空间 */
    overflow-y: auto;
    padding: 16px 0;
    display: flex;
    flex-direction: column;
    min-height: 0; /* 允许flex收缩 */
}

.message {
    margin-bottom: 28px;
    line-height: 1.6;
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.user-message {
    align-self: flex-end;
    max-width: 70%;
    background: linear-gradient(135deg, #a5b4fc, #c7d2fe);
    color: #1e293b;
    padding: 12px 18px;
    border-radius: 20px 20px 6px 20px;
    font-size: 15px;
    box-shadow: 0 3px 12px rgba(165, 180, 252, 0.3);
    font-weight: 500;
}

.ai-message {
    align-self: flex-start;
    width: calc(100% - 60px); /* 固定宽度，减去左边距 */
    max-width: none; /* 移除最大宽度限制 */
    color: #475569;
    padding: 20px 24px;
    border-radius: 12px; /* 恢复统一圆角 */
    position: relative;
    margin-bottom: 20px;
    margin-left: 20px;
    background: linear-gradient(145deg, #fefefe, #f9fafb);
    border: 1px solid #f1f5f9;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
}

/* 创建对话气泡尖角 */
.ai-message::before {
    content: "";
    position: absolute;
    top: 20px;
    left: -8px;
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-right: 8px solid #fefefe;
    z-index: 2;
}

/* 创建对话气泡尖角的边框 */
.ai-message::after {
    content: "";
    position: absolute;
    top: 19px;
    left: -9px;
    width: 0;
    height: 0;
    border-top: 9px solid transparent;
    border-bottom: 9px solid transparent;
    border-right: 9px solid #f1f5f9;
    z-index: 1;
}

/* AI思考加载动画容器 */
.loading-container {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
    border-radius: 12px;
    border: 2px solid #e0e7ff;
    position: relative;
    overflow: hidden;
}

.loading-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(129, 140, 248, 0.2), transparent);
    animation: shimmer 1.8s infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* AI思考旋转动画 */
.loading-spinner {
    width: 28px;
    height: 28px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.loading-spinner::before {
    content: '';
    width: 28px;
    height: 28px;
    border: 3px solid #e0e7ff;
    border-top: 3px solid #4f46e5;
    border-radius: 50%;
    animation: loading-spin 1s linear infinite;
}

.loading-spinner::after {
    content: '🤖';
    position: absolute;
    font-size: 14px;
    animation: loading-pulse 2s ease-in-out infinite;
}

@keyframes loading-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes loading-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.05); }
}

/* AI思考文字动画 */
.loading-container span {
    font-size: 14px;
    font-weight: 500;
    color: #4f46e5;
    position: relative;
    display: flex;
    align-items: center;
}

.loading-container span::after {
    content: '';
    animation: thinking-dots 1.6s infinite;
}

@keyframes thinking-dots {
    0%, 20% { content: ''; }
    33% { content: '.'; }
    66% { content: '..'; }
    100% { content: '...'; }
}

/* 改进思考过程容器 */
.think-container {
    margin-top: 20px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #e0e7ff;
    background: #f8faff;
}

/* 思考过程标题栏 */
.think-toggle {
    background: #eef2ff;
    padding: 12px 16px;
    font-size: 14px;
    color: #5b21b6;
    cursor: pointer;
    display: flex;
    align-items: center;
    border-radius: 0;
    user-select: none;
    font-weight: 500;
    transition: all 0.2s ease;
    position: relative;
}

.think-toggle::before {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid #c7d2fe;
    border-radius: 50%;
    margin-right: 8px;
    flex-shrink: 0;
}

/* 只在思考阶段显示转圈动画 */
.think-toggle.thinking::before {
    border-top: 2px solid #5b21b6;
    animation: loading-spin 1s linear infinite;
}

.think-toggle:hover {
    background: #e0e7ff;
    color: #4c1d95;
}

.think-toggle i.bi-chevron-down {
    margin-left: auto;
    transition: transform 0.3s ease;
    font-size: 14px;
    color: #5b21b6;
}

.think-toggle.active i.bi-chevron-down {
    transform: rotate(180deg);
}

.copy-btn {
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid #c7d2fe;
    color: #5b21b6;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-right: 8px;
    padding: 0;
}

.copy-btn:hover {
    background: #ffffff;
    color: #4c1d95;
    border-color: #4c1d95;
}

/* 思考过程内容区域 */
.think-content {
    background: #ffffff;
    padding: 16px;
    font-size: 14px;
    border-radius: 0;
    line-height: 1.6;
    color: #374151;
    border-top: 1px solid #e0e7ff;
    display: none;
}

/* 思考内容的文本样式 */
.think-content p {
    margin-bottom: 12px;
}

.think-content p:last-child {
    margin-bottom: 0;
}

/* 展开动画 */
.think-content.expanding {
    display: block;
    animation: expandContent 0.3s ease-out;
}

@keyframes expandContent {
    from {
        max-height: 0;
        opacity: 0;
        padding-top: 0;
        padding-bottom: 0;
    }
    to {
        max-height: 1000px;
        opacity: 1;
        padding-top: 16px;
        padding-bottom: 16px;
    }
}

.markdown-content {
    line-height: 1.7;
    font-size: 15px;
    color: #64748b;
}

.markdown-content p {
    margin-bottom: 16px; /* 增加段落间距 */
}

.markdown-content h1, .markdown-content h2, .markdown-content h3, 
.markdown-content h4, .markdown-content h5, .markdown-content h6 {
    color: #475569;
    margin: 24px 0 16px 0;
    font-weight: 600;
}

.markdown-content h2 {
    font-size: 20px;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 8px;
}

.markdown-content h3 {
    font-size: 18px;
    color: #818cf8;
}

.markdown-content pre {
    background-color: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 16px;
    overflow-x: auto;
    margin: 16px 0;
    position: relative;
}

.markdown-content code {
    font-family: 'JetBrains Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
    background-color: #f1f5f9;
    color: #e53e3e;
    padding: 3px 6px;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
}

.markdown-content pre code {
    background-color: transparent;
    color: #2d3748;
    padding: 0;
    border: none;
    font-size: 14px;
}

.markdown-content ul, .markdown-content ol {
    margin: 16px 0;
    padding-left: 28px;
}

.markdown-content li {
    margin-bottom: 8px;
    line-height: 1.6;
}

.markdown-content blockquote {
    border-left: 4px solid #4361ee;
    background-color: #f8faff;
    padding: 16px 20px;
    color: #4a5568;
    margin: 16px 0;
    border-radius: 0 8px 8px 0;
    font-style: italic;
}

.markdown-content strong {
    font-weight: 600;
    color: #475569;
}

.markdown-content em {
    font-style: italic;
    color: #4a5568;
}

/* 优化表格样式 */
.markdown-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 16px 0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.markdown-content th, .markdown-content td {
    border: 1px solid #e2e8f0;
    padding: 12px 16px;
    text-align: left;
}

.markdown-content th {
    background-color: #f7fafc;
    font-weight: 600;
    color: #2d3748;
}

.markdown-content tr:nth-child(even) {
    background-color: #f9fafb;
}

/* 文件附件区域 */
.attached-files {
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px 16px;
    margin: 0 0 12px 0;
    flex-shrink: 0; /* 不被压缩 */
}

.attached-file {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 12px;
    margin-bottom: 12px;
    border-bottom: 1px solid #e5e7eb;
}

.file-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #ebf5ff;
    border-radius: 8px;
    flex-shrink: 0;
}

.file-icon i {
    font-size: 20px;
    color: #4361ee;
}

.file-info {
    flex: 1;
    overflow: hidden;
}

.file-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #374151;
}

.file-size {
    font-size: 12px;
    color: #6b7280;
}

.remove-file-btn {
    background: none;
    border: none;
    color: #9ca3af;
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: none;
    cursor: pointer;
    transition: all 0.2s;
}

.remove-file-btn:hover {
    background-color: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.close-preview-btn {
    background: none;
    border: none;
    color: #9ca3af;
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
}

.close-preview-btn:hover {
    background-color: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.file-prompt {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #6b7280;
    font-size: 13px;
}

/* 输入区域 */
.input-area {
    flex-shrink: 0; /* 不被压缩 */
    min-height: 120px; /* 输入区域最小高度 */
    max-height: 50vh; /* 最多占视窗高度的50% */
    border-top: 1px solid #e5e7eb;
    padding: 16px;
    background-color: white;
    overflow-y: auto; /* 内容过多时显示滚动条 */
}

.thinking-options {
    display: flex;
    justify-content: flex-start;
    gap: 12px;
    margin-top: 12px;
    margin-bottom: 8px;
    padding-left: 4px;
}

.thinking-option {
    background: white;
    border: 1px solid #e5e7eb;
    color: #4b5563;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.thinking-option:hover {
    background-color: #f3f4f6;
    color: #4361ee;
    border-color: #4361ee;
    transform: translateY(-1px);
}

.thinking-option.active {
    background-color: #4361ee;
    color: white;
    border-color: #4361ee;
}

.thinking-option i {
    font-size: 14px;
}

.message-input-wrapper {
    position: relative;
    border: 1px solid #e5e7eb;
    border-radius: 24px;
    background-color: white;
    padding: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
}

#user-input {
    flex: 1;
    border: none;
    padding: 8px 12px;
    font-size: 14px;
    resize: none;
    min-height: 40px;
    max-height: calc(50vh - 80px); /* 减去input-area的padding等空间 */
    outline: none;
    background-color: transparent;
    overflow-y: auto; /* 超过最大高度时显示滚动条 */
}

.input-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.action-btn {
    background: none;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #6b7280;
    transition: all 0.2s;
}

.action-btn:hover {
    background-color: #f3f4f6;
    color: #4361ee;
}

.send-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    background: none;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #4361ee;
    transition: all 0.2s;
    box-shadow: none;
}

.send-btn i {
    font-size: 24px;
}

.send-btn:hover {
    transform: translateY(-2px);
    color: #3850d0;
}

.input-footer {
    display: flex;
    justify-content: center;
    margin-top: 8px;
}

.footer-text {
    font-size: 12px;
    color: #9ca3af;
}

/* 工具菜单 */
.tools-menu {
    position: absolute;
    bottom: 48px;
    right: 48px;
    background-color: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    padding: 8px 0;
    min-width: 180px;
    display: none;
    z-index: 100;
}

.tools-menu.active {
    display: block;
}

.tool-item {
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-color);
    cursor: pointer;
    transition: background-color 0.2s;
}

.tool-item:hover {
    background-color: #f3f4f6;
    color: var(--primary-color);
}

.tool-item i {
    font-size: 16px;
}

/* 知识库选择器样式 - 紧凑版 */
.kb-selector-container {
    width: 100%;
    padding: 0;
    margin-bottom: 12px;
    display: flex;
    justify-content: flex-end;
}

.kb-selector-compact {
    position: relative;
    width: auto;
    max-width: 200px;
    min-width: 130px;
    display: flex;
    align-items: center;
}

.kb-selector-compact .kb-select {
    width: 100%;
    padding: 4px 25px 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

.kb-selector-compact i {
    position: absolute;
    right: 8px;
    color: var(--primary-color);
    font-size: 0.8rem;
    pointer-events: none;
}

.kb-select option {
    background-color: var(--bg-light);
    color: var(--text-primary);
    padding: 8px;
}

.kb-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.2);
} 